package com.hifar.test.oaApi;

import java.io.ByteArrayOutputStream;
import java.util.Map;

import com.hifar.test.oaApi.common.MarshallerUtil;

public class MapConverter implements ApiConverter<Map<String, Object>> {

	@Override
    public String convert(Map<String, Object> s, String f) {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		MarshallerUtil.getMarshaller("json").marshaller(s, os);
		try {
			return os.toString("utf-8");
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@Override
    public Map<String, Object> unConvert(String s, String format) {
		return MarshallerUtil.getMarshaller("json").unmarshaller(s, Map.class);
	}

	@Override
    public Class<Map> getObjectClass() {
		return Map.class;
	}

}
